<!doctype html>
<html lang="zh-CN" data-theme="light">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <meta name="generator" content="VuePress 2.0.0-beta.68" />
    <meta name="theme" content="VuePress Theme Hope 2.0.0-beta.250" />
    <style>
      html {
        background: #fff;
      }

      html[data-theme="dark"] {
        background: #1d1e1f;
      }

      body {
        background: var(--bg-color);
      }
    </style>
    <script>
      const userMode = localStorage.getItem("vuepress-theme-hope-scheme");
      const systemDarkMode =
        window.matchMedia &&
        window.matchMedia("(prefers-color-scheme: dark)").matches;

      if (userMode === "dark" || (userMode !== "light" && systemDarkMode)) {
        document.documentElement.setAttribute("data-theme", "dark");
      }
    </script>
    <meta name="referrer" content="no-referrer"><link rel="icon" href="https://gitee.com/eddie-lucas/images/raw/master/img/logo.jpg"><link rel="icon" href="https://gitee.com/eddie-lucas/images/raw/master/img/logo.png" type="image/png" sizes="512x512"><link rel="icon" href="https://gitee.com/eddie-lucas/images/raw/master/img/logo.png" type="image/png" sizes="192x192"><link rel="manifest" href="/manifest.webmanifest" crossorigin="use-credentials"><meta name="theme-color" content="#46bd87"><link rel="apple-touch-icon" href="https://gitee.com/eddie-lucas/images/raw/master/img/logo.png"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><meta name="msapplication-TileImage" content="https://gitee.com/eddie-lucas/images/raw/master/img/logo.png"><meta name="msapplication-TileColor" content="#ffffff"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"><title>主从复制原理 | 小刘Learning</title><meta name="description" content="">
    <link rel="preload" href="/assets/style-3ede7958.css" as="style"><link rel="stylesheet" href="/assets/style-3ede7958.css">
    <link rel="modulepreload" href="/assets/app-d83e1369.js"><link rel="modulepreload" href="/assets/主从复制原理.html-c35d3468.js"><link rel="modulepreload" href="/assets/plugin-vue_export-helper-c27b6911.js"><link rel="modulepreload" href="/assets/主从复制原理.html-5692886d.js">
    <link rel="prefetch" href="/assets/aboutMe.html-72f014c7.js" as="script"><link rel="prefetch" href="/assets/index.html-69cd5f22.js" as="script"><link rel="prefetch" href="/assets/Java集合.html-f6d1e995.js" as="script"><link rel="prefetch" href="/assets/MyBatis常见问题.html-3782c8f7.js" as="script"><link rel="prefetch" href="/assets/InnoDB的Buffer Pool.html-f0ae2755.js" as="script"><link rel="prefetch" href="/assets/InnoDB的行格式和页结构.html-31890643.js" as="script"><link rel="prefetch" href="/assets/MySQL中的各种锁.html-b819061d.js" as="script"><link rel="prefetch" href="/assets/MySQL中的排序.html-5442bdf2.js" as="script"><link rel="prefetch" href="/assets/MySQL事务与MVCC.html-11dea9ac.js" as="script"><link rel="prefetch" href="/assets/MySQL优化器原理.html-44cdf1f3.js" as="script"><link rel="prefetch" href="/assets/5种IO模型.html-623f6d24.js" as="script"><link rel="prefetch" href="/assets/Netty的线程模型.html-1933240c.js" as="script"><link rel="prefetch" href="/assets/粘包拆包问题.html-e5c58280.js" as="script"><link rel="prefetch" href="/assets/AOF和RDB持久化.html-de83ad53.js" as="script"><link rel="prefetch" href="/assets/Gossip协议.html-9cc1d704.js" as="script"><link rel="prefetch" href="/assets/Redisson看门狗机制.html-8e4e6651.js" as="script"><link rel="prefetch" href="/assets/内存淘汰策略.html-2108cb44.js" as="script"><link rel="prefetch" href="/assets/缓存击穿、穿透、雪崩.html-d043509c.js" as="script"><link rel="prefetch" href="/assets/过期键的删除策略.html-86aae1a3.js" as="script"><link rel="prefetch" href="/assets/NameServer.html-6a201ec6.js" as="script"><link rel="prefetch" href="/assets/消息发送.html-4164a815.js" as="script"><link rel="prefetch" href="/assets/消息持久化.html-ad4aec32.js" as="script"><link rel="prefetch" href="/assets/Spring4.3.x源码阅读.html-ce67a2f8.js" as="script"><link rel="prefetch" href="/assets/过滤器和拦截器的区别.html-c5dbe180.js" as="script"><link rel="prefetch" href="/assets/MySQL安装.html-ce91cf4e.js" as="script"><link rel="prefetch" href="/assets/nvm_node安装.html-c02c4943.js" as="script"><link rel="prefetch" href="/assets/xxl-job源码阅读.html-4a3b4336.js" as="script"><link rel="prefetch" href="/assets/算法补充题.html-82552fdf.js" as="script"><link rel="prefetch" href="/assets/转换函数.html-4e846421.js" as="script"><link rel="prefetch" href="/assets/分布式事务.html-4015f1f4.js" as="script"><link rel="prefetch" href="/assets/深入理解Java虚拟机.html-f58d9b73.js" as="script"><link rel="prefetch" href="/assets/Redis开发与运维.html-8fbbb19d.js" as="script"><link rel="prefetch" href="/assets/Redis设计与实现.html-3d2f28fe.js" as="script"><link rel="prefetch" href="/assets/中级开发（5年内） .html-fe02712d.js" as="script"><link rel="prefetch" href="/assets/初级开发（3年内）.html-669c578d.js" as="script"><link rel="prefetch" href="/assets/高级开发（8年内）.html-8e45d1a0.js" as="script"><link rel="prefetch" href="/assets/apache poi导致的oom.html-ac4f4186.js" as="script"><link rel="prefetch" href="/assets/Spring启动及扫描流程.html-dca86884.js" as="script"><link rel="prefetch" href="/assets/404.html-81a48005.js" as="script"><link rel="prefetch" href="/assets/index.html-2b6ad090.js" as="script"><link rel="prefetch" href="/assets/index.html-30245415.js" as="script"><link rel="prefetch" href="/assets/index.html-c2c088b3.js" as="script"><link rel="prefetch" href="/assets/index.html-f512ec67.js" as="script"><link rel="prefetch" href="/assets/index.html-e1891597.js" as="script"><link rel="prefetch" href="/assets/index.html-b77929dc.js" as="script"><link rel="prefetch" href="/assets/index.html-3e3e3234.js" as="script"><link rel="prefetch" href="/assets/index.html-db16fd88.js" as="script"><link rel="prefetch" href="/assets/index.html-02e59ce2.js" as="script"><link rel="prefetch" href="/assets/index.html-55c7e4fd.js" as="script"><link rel="prefetch" href="/assets/index.html-3b089dfb.js" as="script"><link rel="prefetch" href="/assets/index.html-ac5b8d61.js" as="script"><link rel="prefetch" href="/assets/index.html-a2f3ea26.js" as="script"><link rel="prefetch" href="/assets/index.html-b57e51cb.js" as="script"><link rel="prefetch" href="/assets/index.html-0c321714.js" as="script"><link rel="prefetch" href="/assets/index.html-6266e407.js" as="script"><link rel="prefetch" href="/assets/index.html-00f53358.js" as="script"><link rel="prefetch" href="/assets/index.html-7b46e405.js" as="script"><link rel="prefetch" href="/assets/index.html-219b1b1f.js" as="script"><link rel="prefetch" href="/assets/index.html-ecf569c4.js" as="script"><link rel="prefetch" href="/assets/aboutMe.html-a5377517.js" as="script"><link rel="prefetch" href="/assets/index.html-df94614a.js" as="script"><link rel="prefetch" href="/assets/Java集合.html-25980358.js" as="script"><link rel="prefetch" href="/assets/MyBatis常见问题.html-13559d56.js" as="script"><link rel="prefetch" href="/assets/InnoDB的Buffer Pool.html-2608d2bb.js" as="script"><link rel="prefetch" href="/assets/InnoDB的行格式和页结构.html-b66829d8.js" as="script"><link rel="prefetch" href="/assets/MySQL中的各种锁.html-eda1f1e8.js" as="script"><link rel="prefetch" href="/assets/MySQL中的排序.html-155835e9.js" as="script"><link rel="prefetch" href="/assets/MySQL事务与MVCC.html-5203098d.js" as="script"><link rel="prefetch" href="/assets/MySQL优化器原理.html-580192b8.js" as="script"><link rel="prefetch" href="/assets/5种IO模型.html-e14d32e5.js" as="script"><link rel="prefetch" href="/assets/Netty的线程模型.html-79ec3f0d.js" as="script"><link rel="prefetch" href="/assets/粘包拆包问题.html-ad117100.js" as="script"><link rel="prefetch" href="/assets/AOF和RDB持久化.html-8f530297.js" as="script"><link rel="prefetch" href="/assets/Gossip协议.html-68ce5f80.js" as="script"><link rel="prefetch" href="/assets/Redisson看门狗机制.html-f806e761.js" as="script"><link rel="prefetch" href="/assets/内存淘汰策略.html-58163b51.js" as="script"><link rel="prefetch" href="/assets/缓存击穿、穿透、雪崩.html-d8d78972.js" as="script"><link rel="prefetch" href="/assets/过期键的删除策略.html-b2be5f51.js" as="script"><link rel="prefetch" href="/assets/NameServer.html-6ada07a1.js" as="script"><link rel="prefetch" href="/assets/消息发送.html-08920331.js" as="script"><link rel="prefetch" href="/assets/消息持久化.html-32746c2c.js" as="script"><link rel="prefetch" href="/assets/Spring4.3.x源码阅读.html-3475e320.js" as="script"><link rel="prefetch" href="/assets/过滤器和拦截器的区别.html-56c13477.js" as="script"><link rel="prefetch" href="/assets/MySQL安装.html-c7803a3a.js" as="script"><link rel="prefetch" href="/assets/nvm_node安装.html-736601b9.js" as="script"><link rel="prefetch" href="/assets/xxl-job源码阅读.html-2b98669d.js" as="script"><link rel="prefetch" href="/assets/算法补充题.html-37debf9d.js" as="script"><link rel="prefetch" href="/assets/转换函数.html-44dfb333.js" as="script"><link rel="prefetch" href="/assets/分布式事务.html-e6634dbe.js" as="script"><link rel="prefetch" href="/assets/深入理解Java虚拟机.html-3810cea1.js" as="script"><link rel="prefetch" href="/assets/Redis开发与运维.html-76744132.js" as="script"><link rel="prefetch" href="/assets/Redis设计与实现.html-eccc56a7.js" as="script"><link rel="prefetch" href="/assets/中级开发（5年内） .html-a2fc4d16.js" as="script"><link rel="prefetch" href="/assets/初级开发（3年内）.html-e48a4104.js" as="script"><link rel="prefetch" href="/assets/高级开发（8年内）.html-9138cbdd.js" as="script"><link rel="prefetch" href="/assets/apache poi导致的oom.html-b39dacda.js" as="script"><link rel="prefetch" href="/assets/Spring启动及扫描流程.html-0b604fff.js" as="script"><link rel="prefetch" href="/assets/404.html-742f0851.js" as="script"><link rel="prefetch" href="/assets/index.html-160c66d3.js" as="script"><link rel="prefetch" href="/assets/index.html-bb7b1e80.js" as="script"><link rel="prefetch" href="/assets/index.html-116fe317.js" as="script"><link rel="prefetch" href="/assets/index.html-17f24df8.js" as="script"><link rel="prefetch" href="/assets/index.html-3fe5d15e.js" as="script"><link rel="prefetch" href="/assets/index.html-c894bb5e.js" as="script"><link rel="prefetch" href="/assets/index.html-25b31507.js" as="script"><link rel="prefetch" href="/assets/index.html-8bb87106.js" as="script"><link rel="prefetch" href="/assets/index.html-255fc5d5.js" as="script"><link rel="prefetch" href="/assets/index.html-373a73ca.js" as="script"><link rel="prefetch" href="/assets/index.html-d539e1a9.js" as="script"><link rel="prefetch" href="/assets/index.html-1475787c.js" as="script"><link rel="prefetch" href="/assets/index.html-8073adbe.js" as="script"><link rel="prefetch" href="/assets/index.html-2ff9332c.js" as="script"><link rel="prefetch" href="/assets/index.html-f14ceb6a.js" as="script"><link rel="prefetch" href="/assets/index.html-54082429.js" as="script"><link rel="prefetch" href="/assets/index.html-264a3de2.js" as="script"><link rel="prefetch" href="/assets/index.html-fb62746d.js" as="script"><link rel="prefetch" href="/assets/index.html-81d28dad.js" as="script"><link rel="prefetch" href="/assets/index.html-56062662.js" as="script"><link rel="prefetch" href="/assets/giscus-0b7adcf8.js" as="script"><link rel="prefetch" href="/assets/photoswipe.esm-1464cdb9.js" as="script"><link rel="prefetch" href="/assets/index-e32a7948.js" as="script">
  </head>
  <body>
    <div id="app"><!--[--><!--[--><!--[--><span tabindex="-1"></span><a href="#main-content" class="vp-skip-link sr-only">跳至主要內容</a><!--]--><!--[--><div class="theme-container has-toc"><!--[--><header id="navbar" class="vp-navbar"><div class="vp-navbar-start"><button type="button" class="vp-toggle-sidebar-button" title="Toggle Sidebar"><span class="icon"></span></button><!--[--><!----><!--]--><!--[--><a class="vp-link vp-brand vp-brand" href="/"><img class="vp-nav-logo" src="https://gitee.com/eddie-lucas/images/raw/master/img/logo.svg" alt="小刘Learning"><!----><span class="vp-site-name hide-in-pad">小刘Learning</span></a><!--]--><!--[--><!----><!--]--></div><div class="vp-navbar-center"><!--[--><!----><!--]--><!--[--><nav class="vp-nav-links"><div class="nav-item hide-in-mobile"><a aria-label="首页" class="vp-link nav-link nav-link" href="/"><span class="font-icon icon iconfont icon-shouye" style=""></span>首页<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="后端技术" class="vp-link nav-link nav-link" href="/backend/mysql/MySQL%E4%BA%8B%E5%8A%A1%E4%B8%8EMVCC.html"><span class="font-icon icon iconfont icon-xingqiu" style=""></span>后端技术<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="读书笔记" class="vp-link nav-link nav-link" href="/readNote/redis/Redis%E5%BC%80%E5%8F%91%E4%B8%8E%E8%BF%90%E7%BB%B4.html"><span class="font-icon icon iconfont icon-book" style=""></span>读书笔记<!----></a></div></nav><!--]--><!--[--><!----><!--]--></div><div class="vp-navbar-end"><!--[--><!----><!--]--><!--[--><!----><div class="nav-item vp-repo"><a class="vp-repo-link" href="https://github.com/eddie-lucas" target="_blank" rel="noopener noreferrer" aria-label="GitHub"><svg xmlns="http://www.w3.org/2000/svg" class="icon github-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="github icon" style="width:1.25rem;height:1.25rem;vertical-align:middle;"><path d="M511.957 21.333C241.024 21.333 21.333 240.981 21.333 512c0 216.832 140.544 400.725 335.574 465.664 24.49 4.395 32.256-10.07 32.256-23.083 0-11.69.256-44.245 0-85.205-136.448 29.61-164.736-64.64-164.736-64.64-22.315-56.704-54.4-71.765-54.4-71.765-44.587-30.464 3.285-29.824 3.285-29.824 49.195 3.413 75.179 50.517 75.179 50.517 43.776 75.008 114.816 53.333 142.762 40.79 4.523-31.66 17.152-53.377 31.19-65.537-108.971-12.458-223.488-54.485-223.488-242.602 0-53.547 19.114-97.323 50.517-131.67-5.035-12.33-21.93-62.293 4.779-129.834 0 0 41.258-13.184 134.912 50.346a469.803 469.803 0 0 1 122.88-16.554c41.642.213 83.626 5.632 122.88 16.554 93.653-63.488 134.784-50.346 134.784-50.346 26.752 67.541 9.898 117.504 4.864 129.834 31.402 34.347 50.474 78.123 50.474 131.67 0 188.586-114.73 230.016-224.042 242.09 17.578 15.232 33.578 44.672 33.578 90.454v135.85c0 13.142 7.936 27.606 32.854 22.87C862.25 912.597 1002.667 728.747 1002.667 512c0-271.019-219.648-490.667-490.71-490.667z"></path></svg></a></div><div class="nav-item hide-in-mobile"><button type="button" id="appearance-switch"><svg xmlns="http://www.w3.org/2000/svg" class="icon auto-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="auto icon" style="display:block;"><path d="M512 992C246.92 992 32 777.08 32 512S246.92 32 512 32s480 214.92 480 480-214.92 480-480 480zm0-840c-198.78 0-360 161.22-360 360 0 198.84 161.22 360 360 360s360-161.16 360-360c0-198.78-161.22-360-360-360zm0 660V212c165.72 0 300 134.34 300 300 0 165.72-134.28 300-300 300z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="dark icon" style="display:none;"><path d="M524.8 938.667h-4.267a439.893 439.893 0 0 1-313.173-134.4 446.293 446.293 0 0 1-11.093-597.334A432.213 432.213 0 0 1 366.933 90.027a42.667 42.667 0 0 1 45.227 9.386 42.667 42.667 0 0 1 10.24 42.667 358.4 358.4 0 0 0 82.773 375.893 361.387 361.387 0 0 0 376.747 82.774 42.667 42.667 0 0 1 54.187 55.04 433.493 433.493 0 0 1-99.84 154.88 438.613 438.613 0 0 1-311.467 128z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="light icon" style="display:none;"><path d="M952 552h-80a40 40 0 0 1 0-80h80a40 40 0 0 1 0 80zM801.88 280.08a41 41 0 0 1-57.96-57.96l57.96-58a41.04 41.04 0 0 1 58 58l-58 57.96zM512 752a240 240 0 1 1 0-480 240 240 0 0 1 0 480zm0-560a40 40 0 0 1-40-40V72a40 40 0 0 1 80 0v80a40 40 0 0 1-40 40zm-289.88 88.08-58-57.96a41.04 41.04 0 0 1 58-58l57.96 58a41 41 0 0 1-57.96 57.96zM192 512a40 40 0 0 1-40 40H72a40 40 0 0 1 0-80h80a40 40 0 0 1 40 40zm30.12 231.92a41 41 0 0 1 57.96 57.96l-57.96 58a41.04 41.04 0 0 1-58-58l58-57.96zM512 832a40 40 0 0 1 40 40v80a40 40 0 0 1-80 0v-80a40 40 0 0 1 40-40zm289.88-88.08 58 57.96a41.04 41.04 0 0 1-58 58l-57.96-58a41 41 0 0 1 57.96-57.96z"></path></svg></button></div><!----><!--]--><!--[--><!----><!--]--><button type="button" class="vp-toggle-navbar-button" aria-label="Toggle Navbar" aria-expanded="false" aria-controls="nav-screen"><span><span class="vp-top"></span><span class="vp-middle"></span><span class="vp-bottom"></span></span></button></div></header><!----><!--]--><!----><div class="toggle-sidebar-wrapper"><span class="arrow start"></span></div><aside id="sidebar" class="vp-sidebar"><!--[--><!----><!--]--><ul class="vp-sidebar-links"><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-MySQL" style=""></span><span class="vp-sidebar-title">MySQL</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable active" type="button"><span class="font-icon icon iconfont icon-redis" style=""></span><span class="vp-sidebar-title">Redis</span><span class="vp-arrow down"></span></button><ul class="vp-sidebar-links"><li><!--[--><a aria-label="AOF和RDB持久化" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/backend/redis/AOF%E5%92%8CRDB%E6%8C%81%E4%B9%85%E5%8C%96.html"><!---->AOF和RDB持久化<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="过期键的删除策略" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/backend/redis/%E8%BF%87%E6%9C%9F%E9%94%AE%E7%9A%84%E5%88%A0%E9%99%A4%E7%AD%96%E7%95%A5.html"><!---->过期键的删除策略<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="缓存击穿、穿透、雪崩" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/backend/redis/%E7%BC%93%E5%AD%98%E5%87%BB%E7%A9%BF%E3%80%81%E7%A9%BF%E9%80%8F%E3%80%81%E9%9B%AA%E5%B4%A9.html"><!---->缓存击穿、穿透、雪崩<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="Redisson看门狗机制" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/backend/redis/Redisson%E7%9C%8B%E9%97%A8%E7%8B%97%E6%9C%BA%E5%88%B6.html"><!---->Redisson看门狗机制<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="主从复制原理" class="vp-link nav-link active vp-sidebar-link vp-sidebar-page active nav-link active vp-sidebar-link vp-sidebar-page active" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html"><!---->主从复制原理<!----></a><ul class="vp-sidebar-sub-headers"><li class="vp-sidebar-sub-header"><a aria-label="Redis主从复制是什么？" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#redis主从复制是什么"><!---->Redis主从复制是什么？<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="旧版主从复制" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#旧版主从复制"><!---->旧版主从复制<!----></a><ul class="vp-sidebar-sub-headers"><li class="vp-sidebar-sub-header"><a aria-label="同步" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#同步"><!---->同步<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="命令传播" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#命令传播"><!---->命令传播<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="旧版复制存在的问题" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#旧版复制存在的问题"><!---->旧版复制存在的问题<!----></a><ul class="vp-sidebar-sub-headers"></ul></li></ul></li><li class="vp-sidebar-sub-header"><a aria-label="新版主从复制" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#新版主从复制"><!---->新版主从复制<!----></a><ul class="vp-sidebar-sub-headers"><li class="vp-sidebar-sub-header"><a aria-label="复制偏移量" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#复制偏移量"><!---->复制偏移量<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="复制积压缓冲区" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#复制积压缓冲区"><!---->复制积压缓冲区<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="run ID" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#run-id"><!---->run ID<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="新版主从复制步骤详解" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#新版主从复制步骤详解"><!---->新版主从复制步骤详解<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="两个缓冲区的区别" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/backend/redis/%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%8E%9F%E7%90%86.html#两个缓冲区的区别"><!---->两个缓冲区的区别<!----></a><ul class="vp-sidebar-sub-headers"></ul></li></ul></li></ul><!--]--></li><li><!--[--><a aria-label="内存淘汰策略" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/backend/redis/%E5%86%85%E5%AD%98%E6%B7%98%E6%B1%B0%E7%AD%96%E7%95%A5.html"><!---->内存淘汰策略<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="Gossip协议" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/backend/redis/Gossip%E5%8D%8F%E8%AE%AE.html"><!---->Gossip协议<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li></ul></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-Spring" style=""></span><span class="vp-sidebar-title">Spring</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-a-icons8-mybatis2" style=""></span><span class="vp-sidebar-title">MyBatis</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-xxl-job" style=""></span><span class="vp-sidebar-title">XXL-JOB</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-RocketMQ" style=""></span><span class="vp-sidebar-title">RocketMQ 4.6.0</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-Netty" style=""></span><span class="vp-sidebar-title">Netty</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-tools" style=""></span><span class="vp-sidebar-title">工具安装教程</span><span class="vp-arrow end"></span></button><!----></section></li></ul><!--[--><!----><!--]--></aside><!--[--><main id="main-content" class="vp-page"><!--[--><!--[--><!----><!--]--><!----><nav class="vp-breadcrumb disable"></nav><div class="vp-page-title"><h1><!---->主从复制原理</h1><div class="page-info"><span class="page-author-info" aria-label="作者🖊" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon author-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="author icon"><path d="M649.6 633.6c86.4-48 147.2-144 147.2-249.6 0-160-128-288-288-288s-288 128-288 288c0 108.8 57.6 201.6 147.2 249.6-121.6 48-214.4 153.6-240 288-3.2 9.6 0 19.2 6.4 25.6 3.2 9.6 12.8 12.8 22.4 12.8h704c9.6 0 19.2-3.2 25.6-12.8 6.4-6.4 9.6-16 6.4-25.6-25.6-134.4-121.6-240-243.2-288z"></path></svg><span><span class="page-author-item">小刘Learning</span></span><span property="author" content="小刘Learning"></span></span><!----><span class="page-date-info" aria-label="写作日期📅" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon calendar-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="calendar icon"><path d="M716.4 110.137c0-18.753-14.72-33.473-33.472-33.473-18.753 0-33.473 14.72-33.473 33.473v33.473h66.993v-33.473zm-334.87 0c0-18.753-14.72-33.473-33.473-33.473s-33.52 14.72-33.52 33.473v33.473h66.993v-33.473zm468.81 33.52H716.4v100.465c0 18.753-14.72 33.473-33.472 33.473a33.145 33.145 0 01-33.473-33.473V143.657H381.53v100.465c0 18.753-14.72 33.473-33.473 33.473a33.145 33.145 0 01-33.473-33.473V143.657H180.6A134.314 134.314 0 0046.66 277.595v535.756A134.314 134.314 0 00180.6 947.289h669.74a134.36 134.36 0 00133.94-133.938V277.595a134.314 134.314 0 00-133.94-133.938zm33.473 267.877H147.126a33.145 33.145 0 01-33.473-33.473c0-18.752 14.72-33.473 33.473-33.473h736.687c18.752 0 33.472 14.72 33.472 33.473a33.145 33.145 0 01-33.472 33.473z"></path></svg><span><!----></span><meta property="datePublished" content="2024-10-17T09:42:46.000Z"></span><!----><span class="page-reading-time-info" aria-label="阅读时间⌛" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon timer-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="timer icon"><path d="M799.387 122.15c4.402-2.978 7.38-7.897 7.38-13.463v-1.165c0-8.933-7.38-16.312-16.312-16.312H256.33c-8.933 0-16.311 7.38-16.311 16.312v1.165c0 5.825 2.977 10.874 7.637 13.592 4.143 194.44 97.22 354.963 220.201 392.763-122.204 37.542-214.893 196.511-220.2 389.397-4.661 5.049-7.638 11.651-7.638 19.03v5.825h566.49v-5.825c0-7.379-2.849-13.981-7.509-18.9-5.049-193.016-97.867-351.985-220.2-389.527 123.24-37.67 216.446-198.453 220.588-392.892zM531.16 450.445v352.632c117.674 1.553 211.787 40.778 211.787 88.676H304.097c0-48.286 95.149-87.382 213.728-88.676V450.445c-93.077-3.107-167.901-81.297-167.901-177.093 0-8.803 6.99-15.793 15.793-15.793 8.803 0 15.794 6.99 15.794 15.793 0 80.261 63.69 145.635 142.01 145.635s142.011-65.374 142.011-145.635c0-8.803 6.99-15.793 15.794-15.793s15.793 6.99 15.793 15.793c0 95.019-73.789 172.82-165.96 177.093z"></path></svg><span>大约 8 分钟</span><meta property="timeRequired" content="PT8M"></span><!----><!----></div><hr></div><div class="toc-place-holder"><aside id="toc"><!--[--><!----><!--]--><div class="toc-header">此页内容<button type="button" class="print-button" title="打印"><svg xmlns="http://www.w3.org/2000/svg" class="icon print-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="print icon"><path d="M819.2 364.8h-44.8V128c0-17.067-14.933-32-32-32H281.6c-17.067 0-32 14.933-32 32v236.8h-44.8C145.067 364.8 96 413.867 96 473.6v192c0 59.733 49.067 108.8 108.8 108.8h44.8V896c0 17.067 14.933 32 32 32h460.8c17.067 0 32-14.933 32-32V774.4h44.8c59.733 0 108.8-49.067 108.8-108.8v-192c0-59.733-49.067-108.8-108.8-108.8zM313.6 160h396.8v204.8H313.6V160zm396.8 704H313.6V620.8h396.8V864zM864 665.6c0 25.6-19.2 44.8-44.8 44.8h-44.8V588.8c0-17.067-14.933-32-32-32H281.6c-17.067 0-32 14.933-32 32v121.6h-44.8c-25.6 0-44.8-19.2-44.8-44.8v-192c0-25.6 19.2-44.8 44.8-44.8h614.4c25.6 0 44.8 19.2 44.8 44.8v192z"></path></svg></button></div><div class="toc-wrapper"><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#redis主从复制是什么">Redis主从复制是什么？</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#旧版主从复制">旧版主从复制</a></li><li><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#同步">同步</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#命令传播">命令传播</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#旧版复制存在的问题">旧版复制存在的问题</a></li><!----><!--]--></ul></li><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#新版主从复制">新版主从复制</a></li><li><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#复制偏移量">复制偏移量</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#复制积压缓冲区">复制积压缓冲区</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#run-id">run ID</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#新版主从复制步骤详解">新版主从复制步骤详解</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#两个缓冲区的区别">两个缓冲区的区别</a></li><!----><!--]--></ul></li><!--]--></ul><div class="toc-marker" style="top:-1.7rem;"></div></div><!--[--><!----><!--]--></aside></div><!--[--><!----><!--]--><div class="theme-hope-content"><h2 id="redis主从复制是什么" tabindex="-1"><a class="header-anchor" href="#redis主从复制是什么" aria-hidden="true">#</a> Redis主从复制是什么？</h2><p>redis主从复制指，一个redis主节点，可以将数据复制到一个或多个redis从节点，从节点从主节点获取数据并保持同步</p><p>主从架构可以实现读写分离，写操作请求主节点，读操作请求从节点，这样就能够减轻主节点压力</p><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017111302650.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><h2 id="旧版主从复制" tabindex="-1"><a class="header-anchor" href="#旧版主从复制" aria-hidden="true">#</a> 旧版主从复制</h2><blockquote><p>redis2.8版本之前是旧版本的主从复制，存在一些问题，先从旧版本来理解整个过程，再过渡到新版本订单主从复制</p></blockquote><p>redis的复制功能分为<strong>2个操作：同步，命令传播</strong></p><ol><li>同步：将从节点的数据库状态更新至主节点当前所处的数据库状态</li><li>命令传播：当主节点数据库状态被修改，导致主从节点的数据状态不一致，主节点将写命令发送给从节点，让主从节点的数据库重新回到一致状态</li></ol><h3 id="同步" tabindex="-1"><a class="header-anchor" href="#同步" aria-hidden="true">#</a> 同步</h3><p>主从复制的第一步是执行同步操作，从节点对主节点的同步操作通过向主节点发送<code>SYNC</code>命令来完成，SYNC命令执行步骤如下：</p><ol><li>从节点向主节点发送<code>SYNC</code>命令</li><li>主节点收到SYNC命令后，执行<code>BGSAVE</code>命令，在后台生成RDB文件，并<strong>使用一个复制缓冲区（replicaiton buffer）记录从现在开始执行的所有写命令</strong></li><li>RDB文件生成后，主节点将RDB文件发送给从节点，从节点接收后，载入RDB文件</li><li>主节点将缓冲区的所有写命令发送给从节点，从节点执行这些命令，将自己的数据库状态更新至主节点当前状态</li></ol><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017112941480.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><p>[<strong>举例</strong>]一个具体的过程</p><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017135331618.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><h3 id="命令传播" tabindex="-1"><a class="header-anchor" href="#命令传播" aria-hidden="true">#</a> 命令传播</h3><p>在同步操作执行完后，主从节点数据保持一致，但是这种一致状态并不是一成不变的，每当主节点执行写命令，主节点数据就有可能被修改，导致和从节点数据不一致</p><p>例如，在刚执行同步操作之后，主节点删除了一个kv，但是这个kv仍然在从节点上，此时主从节点就是数据不一致的</p><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017135831877.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><p>为了让主从节点继续保持一致，主节点需要进行命令传播操作，即主节点将写命令发送给从节点，然后从节点执行这个写命令，主从节点就回到了一致状态</p><h3 id="旧版复制存在的问题" tabindex="-1"><a class="header-anchor" href="#旧版复制存在的问题" aria-hidden="true">#</a> 旧版复制存在的问题</h3><p>首先，主从复制分为2种情况：</p><ul><li>初次复制：从节点第一次复制该主节点</li><li>断线后重复制：处于命令传播阶段的主从节点因为网络原因中断了复制，从节点自动重新连接主节点后，并继续复制主节点</li></ul><p>对于初次复制，旧版复制能很好的完成任务，但是<strong>对于断线后重复制，旧版复制功能效率太低了</strong></p><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017141715763.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><p>从上图<code>T10093</code>可以看到，断线后重复制，需要同步的只是部分kv，但是却再次生成了全量数据的RDB文件，为了让从节点补足一小部分缺失的数据，却要让主节点重新执行一次SYNC命令，再次生成全量数据的RDB文件，这种做法效率很低</p><blockquote><p>补充介绍SYNC命令</p></blockquote><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017142318881.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><h2 id="新版主从复制" tabindex="-1"><a class="header-anchor" href="#新版主从复制" aria-hidden="true">#</a> 新版主从复制</h2><p>为了解决旧版复制功能的问题，redis从2.8版本开始，使用<code>PSYNC</code>命令代替SYNC命令来执行复制时的同步操作</p><p><strong>PSYNC有完整重同步和部分重同步两种模式，也称为全量同步，增量同步</strong>：</p><ul><li>完整重同步：用于处理初次复制的情况，和SYNC执行步骤基本一致，都是通过主节点创建并发送RDB文件，以及向从节点发送保存在复制缓冲区（replication buffer）的写命令来进行同步</li><li>部分重同步：用于处理断线后的重复制情况，当断线重连时，如果满足条件，主节点会将断线期间执行的命令发送给从节点，从节点只需要接收并执行这部分命令，就能和主节点保持一致</li></ul><blockquote><p>在了解新版主从复制之前，需要先掌握几个概念</p></blockquote><h3 id="复制偏移量" tabindex="-1"><a class="header-anchor" href="#复制偏移量" aria-hidden="true">#</a> 复制偏移量</h3><p>主从节点分别维护一个复制偏移量offset：</p><ul><li>主节点每次向从节点传播N个字节的数据时，就将自己的offset+N</li><li>从节点每次收到数据，就将自己的offset+N</li></ul><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017155516613.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><p>如果主从节点处于一致状态，则offset值相等，如果不相等，offset值不同，上图中，A节点断线重连后，向主节点发送PSYNC命令进行同步，执行完整重同步还是部分重同步，跟复制积压缓冲区有关</p><h3 id="复制积压缓冲区" tabindex="-1"><a class="header-anchor" href="#复制积压缓冲区" aria-hidden="true">#</a> 复制积压缓冲区</h3><p>复制积压缓冲区（repl_backlog_buffer），是由主节点维护的一个<strong>固定长度</strong>的<strong>先进先出的队列</strong>，也被叫做环形缓冲区，默认大小为1MB，主节点上只有1个复制积压缓冲区</p><p>当主节点进行命令传播时，不仅会将写命令发送给从节点，还会将写命令写入到复制积压缓冲区</p><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017160418037.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><p>当从节点断线重连，从节点通过PSYNC命令将自己的offset发送给主节点，主节点根据offset来决定执行何种同步：</p><ul><li>如果offset+1仍然在复制积压缓冲区中，因为时FIFO队列，说明offset后面的数据都能找得到，则主节点会执行部分重同步</li><li>如果offset+1不在复制积压缓冲区，说明最少有一条数据丢失了（即offset+1这条数据丢失了），因为是固定大小的队列，队列满了的话，队尾再来新的数据，队头的数据就需要出队了，则主节点会执行完整重同步</li></ul><h3 id="run-id" tabindex="-1"><a class="header-anchor" href="#run-id" aria-hidden="true">#</a> run ID</h3><p>每个redis节点，不管是主节点还是从节点，都有自己的run ID（运行 ID），run ID在服务启动时自动生成</p><ul><li>初次复制的时候，主节点会将自己的run ID发送给从节点</li><li>从节点断线重连到一个主节点时，会向其发送之前保存的run ID</li><li>如果与主节点run ID相同，说明这次重连的就是之前复制的主节点，可以继续执行部分重同步</li><li>如果与主节点run ID不同，说明这次重连的不是之前复制的主节点，只能执行完整重同步</li></ul><h3 id="新版主从复制步骤详解" tabindex="-1"><a class="header-anchor" href="#新版主从复制步骤详解" aria-hidden="true">#</a> 新版主从复制步骤详解</h3><blockquote><p>完整重同步，全量同步</p></blockquote><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017153739326.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><ul><li>从节点发送<code>psync ? -1</code>，第一个参数是run ID，第初次同步不知道，于是传递？，第二个参数是offset，初次同步为-1</li><li>主节点收到命令，判断是全量同步，返回<code>fullresync runid offset</code> ，从节点会存储这两个值</li><li>主节点执行<code>bgsave</code>生成RDB文件，在生成过程中的写命令会存储到复制缓冲区<code>replication buffer</code></li><li>RDB文件生成后，主节点将其发送给从节点，从节点清空旧数据，加载RDB文件</li><li>加载完成后，主节点将复制缓冲区<code>replication buffer</code>中的写命令发送给从节点执行，达到主从一致</li></ul><p>待同步完毕，主从节点会保持一个长连接，主节点会通过这个连接将后续的写命令传递给从节点</p><blockquote><p>部分重同步，增量同步</p></blockquote><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017154119591.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017153530183.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure><p>当主从节点因为网络原因断开，然后重连的时候，如果条件满足，会进行部分重同步：</p><ul><li>从节点发送psync命令，如果run ID和主节点的相同，并且offset+1在复制积压缓冲区（repl_backlog_buffer）中，则可以进行部分重同步，向从节点响应<code>continue</code></li><li>主节点根据offset进行定位，将 <strong>复制积压缓冲区</strong> 中需要发送的写命令放入到 复<strong>制缓冲区</strong> ，再发送到从节点</li><li>从节点执行收到的写命令，达到主从一致</li></ul><h3 id="两个缓冲区的区别" tabindex="-1"><a class="header-anchor" href="#两个缓冲区的区别" aria-hidden="true">#</a> 两个缓冲区的区别</h3><ul><li><p>复制缓冲区：</p><ul><li>replicaiton buffer，因为不同从节点的同步速度不一样，<strong>主节点会为每个从节点创建一个复制缓冲区</strong>，用于记录生成RDB文件过程中主节点执行的写命令，实时传输写命令，可以理解为主要作用与全量同步</li><li>大小是动态的，因为对于同步速度较慢的从节点，需要更多的内存缓存数据</li><li>复制缓冲区的大小由<code>client-output-buffer-limit slave {hard limit} {soft limit} {soft seconds}</code>配置，默认值为client-output-buffer-limit slave 256MB 64MB 60，其含义是：如果buffer大于256MB，或者连续60s大于64MB，则主节点会断开与该从节点的连接。</li></ul></li><li><p>复制积压缓冲区：repl_backlog_buffer，<strong>主节点只有一个复制积压缓冲区</strong>，用于增量同步，存储最近的写命令，同时还会存储该写命令对应的offset，默认大小为1MB。因为增量同步效率更高，所以可以适当增加其大小</p></li></ul><figure><img src="https://gitee.com/eddie-lucas/images/raw/master/img/image-20241017172207490.png" alt="" tabindex="0" loading="lazy"><figcaption></figcaption></figure></div><!--[--><!----><!--]--><footer class="page-meta"><div class="meta-item edit-link"><a href="https://github.com/eddie-lucas/edit/main/src/backend/redis/主从复制原理.md" rel="noopener noreferrer" target="_blank" aria-label="编辑此页" class="nav-link label"><!--[--><svg xmlns="http://www.w3.org/2000/svg" class="icon edit-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="edit icon"><path d="M430.818 653.65a60.46 60.46 0 0 1-50.96-93.281l71.69-114.012 7.773-10.365L816.038 80.138A60.46 60.46 0 0 1 859.225 62a60.46 60.46 0 0 1 43.186 18.138l43.186 43.186a60.46 60.46 0 0 1 0 86.373L588.879 565.55l-8.637 8.637-117.466 68.234a60.46 60.46 0 0 1-31.958 11.229z"></path><path d="M728.802 962H252.891A190.883 190.883 0 0 1 62.008 771.98V296.934a190.883 190.883 0 0 1 190.883-192.61h267.754a60.46 60.46 0 0 1 0 120.92H252.891a69.962 69.962 0 0 0-69.098 69.099V771.98a69.962 69.962 0 0 0 69.098 69.098h475.911A69.962 69.962 0 0 0 797.9 771.98V503.363a60.46 60.46 0 1 1 120.922 0V771.98A190.883 190.883 0 0 1 728.802 962z"></path></svg><!--]-->编辑此页<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></div><div class="meta-item git-info"><div class="update-time"><span class="label">上次编辑于: </span><!----></div><div class="contributors"><span class="label">贡献者: </span><!--[--><!--[--><span class="contributor" title="email: 761404955@qq.com">Lucas</span><!--]--><!--]--></div></div></footer><nav class="vp-page-nav"><a aria-label="Redisson看门狗机制" class="vp-link nav-link prev nav-link prev" href="/backend/redis/Redisson%E7%9C%8B%E9%97%A8%E7%8B%97%E6%9C%BA%E5%88%B6.html"><div class="hint"><span class="arrow start"></span>上一页</div><div class="link"><!---->Redisson看门狗机制</div></a><a aria-label="内存淘汰策略" class="vp-link nav-link next nav-link next" href="/backend/redis/%E5%86%85%E5%AD%98%E6%B7%98%E6%B1%B0%E7%AD%96%E7%95%A5.html"><div class="hint">下一页<span class="arrow end"></span></div><div class="link">内存淘汰策略<!----></div></a></nav><div id="comment" class="giscus-wrapper input-top" style="display:none;"><div class="loading-icon-wrapper" style="display:flex;align-items:center;justify-content:center;height:96px"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" preserveAspectRatio="xMidYMid" viewBox="25 25 50 50"><animateTransform attributeName="transform" type="rotate" dur="2s" keyTimes="0;1" repeatCount="indefinite" values="0;360"></animateTransform><circle cx="50" cy="50" r="20" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round"><animate attributeName="stroke-dasharray" dur="1.5s" keyTimes="0;0.5;1" repeatCount="indefinite" values="1,200;90,200;1,200"></animate><animate attributeName="stroke-dashoffset" dur="1.5s" keyTimes="0;0.5;1" repeatCount="indefinite" values="0;-35px;-125px"></animate></circle></svg></div></div><!--[--><!----><!--]--><!--]--></main><!--]--><footer class="vp-footer-wrapper"><div class="vp-footer">记录，分享自己的学习过程.....</div><div class="vp-copyright">Copyright © 2025 小刘Learning</div></footer></div><!--]--><!--]--><!----><!----><!--]--></div>
    <script type="module" src="/assets/app-d83e1369.js" defer></script>
  </body>
</html>
